package com.example.demo01.controller;

import com.example.demo01.pojo.FormInfo;
import com.example.demo01.pojo.Record;
import com.example.demo01.service.FormInfoService;
import com.example.demo01.service.RecordService;
import com.example.demo01.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private RecordService recordService;
    @Autowired
    private FormInfoService formInfoService;


    @PostMapping("/user/post")
    public String userPost(String username, String name,String time, String phone, String location, String health,Model model){
        //1、生成record，插入record表
        //2、用户提交打卡信息过来，更新isPostToday, isPostToday="是"
        //3、重定向到打卡完的界面，防止表单重复提交
        Record record=new Record(null, username,name,time,phone,location,health);
        recordService.addRecord(record);

        FormInfo formInfo=new FormInfo(username,name,phone,location,health,"是");
        formInfoService.updateFormInfo(formInfo);

        model.addAttribute("record", record);
        System.out.println(record);
        return "user";
    }

    @RequestMapping("/user/goToPostedPage")
    public String goToPostedPage(Model model){


        return "user";
    }

}
